const app = getApp();
Page({
    data: {
        product:{},
        id:'',
        StatusBar: app.globalData.StatusBar + 6,
        TabbarBot: app.globalData.tabbar_bottom,
        swiperlist: [],
    },
    onLoad: function (options) {
        let that = this;
        that.setData({
          id:options.id
        })
        this.ProductInfo(this.data.id)
    },

    ProductInfo:function(productId){
      let imglist = []
      wx.request({
        url: 'http://localhost:8989/product/' + productId,
        method:"GET",
        success: (result) => {
          for(let i=1; i < 6; i ++){
            imglist.push(result.data.data.image + i + "_big.png")
          }
          this.setData({
            product: result.data.data,
            swiperlist: imglist
          })
        },
        fail: (err) => {},
        complete: (res) => {},
      })
    },
    AddCart:function(){
      let _this = this
      wx.getStorage({
        key:'user',
        success:(result) => {
          console.log(result)
          wx.request({
            method:"POST",
            url: 'http://localhost:8989/cart/addOne',
            data:{
              uid: result.data.uid,
              pid: _this.data.product.id,
              price: _this.data.product.price,
              createdUser: result.data.username,
              num: 1
            },
            success:(res) => {
              console.log(res)
            }
          })
        }
      })
    }
});
